
package column


import (
	"github.com/treelab/updatecolumn/models"
)

  func instanceType() int32 {
    return models.Datetime
  }


  deleteColumnEdges(command: UpdateColumn_v2, o: CommonOptions) {
    const { column } = command;
    o.delQuads.push(
      ...this.dgraphHelperService.getRemoveEdgeQuads(column.uid!, [
        'dateFormat',
        'includeTime',
        'timeFormat',
        'useGMT',
      ]),
    );
    return this;
  }

  public hasNothingToUpdate(command: UpdateColumn_v2) {
    const { column } = command;
    const dateColumnConfig = command.columnConfig as DateTimeColumnConfig;
    return (
      column.columnType === this.instanceType &&
      column.dateFormat === dateColumnConfig.dateFormat &&
      column.includeTime === dateColumnConfig.includeTime &&
      column.timeFormat === dateColumnConfig.timeFormat &&
      column.useGMT === dateColumnConfig.useGMT
    );
  }

  async updateColumn(
    command: UpdateColumn_v2,
    o: CommonOptions,
    helper: { rows?: Row[]; columnCopy?: Column; referenceColumns?: Column[]; userGroup?: any },
  ) {
    await super.updateColumn(command, o, helper);

    const { column, columnConfig } = command;
    const { dateFormat, includeTime, timeFormat, useGMT } = columnConfig as DateTimeColumnConfig;

    column.dateFormat = dateFormat;
    column.includeTime = includeTime;
    column.timeFormat = timeFormat;
    column.useGMT = useGMT;

    return this;
  }

  async convertColumn(
    command: UpdateColumn_v2,
    o: CommonOptions,
    helper: { rows?: Row[]; columnCopy?: Column; referenceColumns?: Column[]; userGroup?: any },
  ) {
    await this.defaultConvert({ command }, o, helper);
    return this;
  }

